---
import { InterfaceDocumentation } from './ReferenceDocumentation';
import { getFrameworkFromPath } from '@features/docs/utils/urlPaths';
import { getJsonFile } from '@utils/pages';
import { getEntry } from 'astro:content';
import { getIsDev } from '@utils/env';

const { interfaceName, overrideSrc, names, exclude, config, wrapNamesAt } = Astro.props;

const framework = getFrameworkFromPath(Astro.url.pathname);

let overrides = {};
if (overrideSrc) {
    // NOTE: Need to remove `.json` for getEntry
    const overrideFileName = overrideSrc.replace('.json', '');
    const overridesEntry = await getEntry('interface-documentation', overrideFileName);
    if (!overridesEntry) {
        const message = `InterfaceDocumentation source not found: src/content/interface-documentation/${overrideFileName}.json`;
        if (getIsDev()) {
            console.error(message);
        } else {
            throw new Error(message);
        }
    } else {
        overrides = overridesEntry.data;
    }
}

const interfaceLookup = getJsonFile('reference/interfaces.AUTO.json');
const codeLookup = getJsonFile('reference/doc-interfaces.AUTO.json');
// TODO: Remove?
const htmlLookup = getJsonFile('reference/doc-interfaces.HTML.json');
---

<InterfaceDocumentation
    client:load
    interfaceName={interfaceName}
    framework={framework}
    overrides={overrides}
    names={names}
    exclude={exclude}
    wrapNamesAt={wrapNamesAt}
    config={config}
    interfaceLookup={interfaceLookup}
    codeLookup={codeLookup}
    htmlLookup={htmlLookup}
/>
